package dymnd.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MessagePane extends JComponent implements Runnable, MouseListener{
	
	String message = "Loading...";
	int fps = 30;
	
	int increment = 5;
	final int MAX_ALPHA = 100;
	final int MIN_ALPHA = 10;
	int alpha = MAX_ALPHA;
	boolean rampUp = true;
	public MessagePane(String[] messages)	{
		
	}
	
	public MessagePane(String message)	{
		this.message = message;
		addMouseListener(this);
	}
	
	public void run()	{
		while(!Thread.interrupted())	{
			
			if(rampUp)	{
				if(alpha <= MAX_ALPHA)	{
					alpha += increment;
				}
				else	{
					rampUp = false;
					continue;
				}
			}
			else	{
				if(alpha >= MIN_ALPHA)	{
					alpha -= increment;
				}
				else	{
					rampUp = true;
					continue;
				}
			}
			
			repaint();
			try	{
				Thread.sleep(1000 / fps);
				Thread.yield();
			}	catch(Exception x)	{
				break;
			}
		}
		
	}
	
	public void paintComponent(Graphics arg0)	{
		Graphics2D g = (Graphics2D) arg0;
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g.setColor(new Color(0, 0, 0, alpha));
		g.setFont(new Font("Arial", Font.BOLD, 30));
		g.drawString(message, getWidth() / 2 - 100, getHeight() / 2 - 50);
		
	}
	public void mouseReleased(MouseEvent e)	{}
	public void mousePressed(MouseEvent e)	{}
	public void mouseClicked(MouseEvent e)	{}
	public void mouseEntered(MouseEvent e)	{}
	public void mouseExited(MouseEvent e)	{}
	
}
